package com.hualan.sfzy.controller.consult;

import com.hualan.sfzy.model.entity.ExpertiseAreas;
import com.hualan.sfzy.service.impl.consult.ExpertiseAreasServiceImpl;
import com.hualan.sfzy.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/expertiseAreas")
// 咨询师擅长领域信息控制类

public class ExpertiseAreasController {
    @Autowired
    private ExpertiseAreasServiceImpl service;

    @PostMapping
    // 添加咨询师擅长领域信息
    public Result add(@RequestBody ExpertiseAreas entity) {
        return service.add(entity) > 0 ? Result.success() : Result.error();
    }

    @PutMapping
    // 修改咨询师擅长领域信息
    public Result edit(@RequestBody ExpertiseAreas entity) {
        return service.edit(entity) > 0 ? Result.success() : Result.error();
    }

    @DeleteMapping("/{id}")
    // 根据 id 删除咨询师擅长领域信息
    // 没有批量删除
    public Result remove(@PathVariable("id") Integer id) {
        return service.remove(id) > 0 ? Result.success() : Result.error();
    }

    @GetMapping
    // 查找全部咨询师擅长领域信息
    public Result find() {
        return Result.success(service.find());
    }

    @GetMapping("/{id}")
    // 根据 id 获取咨询师擅长领域信息
    public Result findById(@PathVariable("id") Integer id) {
        return Result.success(service.findById(id));
    }

    @GetMapping("/page")
    // 分页查询咨询师擅长领域信息
    public Result findPage(
            @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
            ExpertiseAreas entity) {
        return Result.success(service.findPage(pageNum, pageSize, entity));
    }


}
